/**
 * Created by guillaume on 16/01/14.
 */
function textboxInitEdit($w) {
	$('.page.active ul.gridster').data('gridster').resize_widget($w, 2, 2);
	var siblingsEdit = $w.siblings('.edit');
	if(siblingsEdit.length > 0){
		$(document).ajaxSuccess(function() {
		  loadTinyMce($w);
		});
		siblingsEdit.find('form').submit();
	}
	else
		loadTinyMce($w);
}

function textboxInitSave($w) {
    return $w.find('#WidgetValue').tinymce().getContent();
}

function textboxInitView($w) {
	tinymce.remove('textarea');
}

function loadTinyMce($w){
    $w.find('#WidgetValue').tinymce({
        // Location of TinyMCE script
        menubar : false,
        resize: false,
        toolbar: "styleselect | bold italic | alignleft aligncenter alignright alignjustify",
		content_css : "/css/formats.css",
		height: 244
    });
	tinymce.execCommand('mceAddControl',true,'WidgetValue');
}